package net.huashitong.synthetical.question.service;

import com.sirdc.modules.core.dao.BaseDao;
import com.sirdc.modules.sys.base.StringPKService;
import com.sirdc.modules.sys.service.SysTableService;
import net.huashitong.synthetical.question.dao.SupervisionTaskDao;
import net.huashitong.synthetical.question.entity.SupervisionLog;
import net.huashitong.synthetical.question.entity.SupervisionTask;
import net.huashitong.synthetical.question.filter.SupervisionTaskFilter;
import net.huashitong.synthetical.question.filter.TaskLogFilter;
import net.huashitong.util.UtilsTools;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.util.List;

@Service
public class SupervisionTaskService extends StringPKService<SupervisionTask> {
    @Override
    protected BaseDao<SupervisionTask, String> getDao() {
        return dao;
    }

    //保存前会自动调用，设置主键ID
    @Override
    protected void beforeSave(SupervisionTask obj) {
        obj.setSysId(tableService.updateMaxSysId("t_bnp_supervision_task", null));
    }

    @Autowired
    private SupervisionLogService supervisionLogService;

    @Autowired
    private SysTableService tableService;

    @Autowired
    private SupervisionTaskDao dao;


    /**
     * 查询任务主要入口
     * @param filter
     * @return
     */
    public List<SupervisionTask> getTaskLists(SupervisionTaskFilter filter)
    {
        return dao.getMissinTask(filter);
    }


    /**
     * 修改任务
     * @param filter
     * @param task
     */
    public void updateTaskJob(SupervisionTaskFilter filter,SupervisionTask task)
    {
       // NodeTaskRecord nodeRecord  = new NodeTaskRecord();
       // nodeRecord.setSource(task.getTaskStage());
        BeanUtils.copyProperties(filter,task);
       // nodeRecord.setTarget();
        update(task);




    }

    public List<SupervisionLog> querySupervisionLogByTaskId(String taskId){
        TaskLogFilter filter = new TaskLogFilter();
        filter.setTaskId(taskId);
        List<SupervisionLog> list = supervisionLogService.querySupervisionLogs(filter);
        return list;
    }


//保存收到新建任务
    public void saveSupervisionTask(SupervisionTaskFilter filter){

        SupervisionTask task=new SupervisionTask();
        BeanUtils.copyProperties(filter,task);
        task.setTasktimes("1"); //督查次数默认1
        task.setAaa001("1");
        task.setTaskResult("0"); //责任单位完成情况默认为0
        task.setSupervisionResult("0");//督查组完成情况默认为0
        task.setRespResult("0");//责任单位完成情况默认为0
        task.setStartDate(UtilsTools.getCurrentDate()); // 任务开始时间默认为当前日期
        task.setPlanEndDate(UtilsTools.getCurrentDate()); // 任务开始时间默认为当前日期
        task.setIsfeedback("0");//是否反馈攻坚办
        task.setTaskDate("15");
        try {
            task.setPlanEndDate(UtilsTools.plusDay(15,UtilsTools.getCurrentDate())); //设置结束时间
        } catch (ParseException e) {
            e.printStackTrace();
        }

        save(task);
    }
//事项处理生成任务
    public void saveSupervisionTask1(SupervisionTaskFilter filter){
        SupervisionTask task=new SupervisionTask();
        BeanUtils.copyProperties(filter,task);
        save(task);
    }
    public void saveTasktoSys()
    {
        dao.savetask();
    }

}
